package org.elanfox.intellicommunity.msg.server;

import io.netty.channel.ChannelFuture;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author allan
 * @version 1.0.0
 * @date 2019/12/11
 */
@SpringBootApplication(scanBasePackages = "org.elanfox.intellicommunity")
public class MsgServerApplication implements CommandLineRunner {
    @Autowired
    private NettyServer nettyServer;

    public static void main(String[] args) {
        SpringApplication.run(MsgServerApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        ChannelFuture channelFuture = nettyServer.start();

        Runtime.getRuntime().addShutdownHook(new Thread(() -> nettyServer.close()));

        //服务端管道关闭的监听器并同步阻塞,直到channel关闭,线程才会往下执行,结束进程
        channelFuture.channel().closeFuture().syncUninterruptibly();
    }
}
